package cn.arikeky.controller;

import cn.arikeky.User;
import cn.arikeky.feign.UserServer;
import cn.arikeky.feign.UserServerBlockFallback;
import cn.arikeky.feign.UserServerBlockHandler;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderController {

    // 注入feign接口
    @Autowired
    private UserServer userServer;


    @GetMapping("/{id}")
    @SentinelResource(value = "order-server-getById", blockHandler = "getByIdBlockHandler", blockHandlerClass = UserServerBlockHandler.class,
                        fallback = "getByIdFallback", fallbackClass = UserServerBlockFallback.class)
    public User getById(@PathVariable("id") Long id){
        int i = 1/0;
        return userServer.getById(id);
    }

//    public User getByIdBlockHandler(Long id, BlockException exception){
//        exception.printStackTrace();
//        return new User(-1L,"我被限流了","稍等再来");
//    }

//        public User getByIdFallback(Long id, Throwable throwable){
//        return new User(-1L,"我被熔断了","别再进来了！");
//    }

}
